package com.smart_campus.teg.controller;

import com.smart_campus.sys.common.ActiveUser;
import com.smart_campus.sys.common.DataGridView;
import com.smart_campus.sys.common.ResultObj;
import com.smart_campus.sys.domain.User;
import com.smart_campus.teg.domain.Major;
import com.smart_campus.teg.service.MajorService;
import com.smart_campus.teg.vo.MajorVo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @aytgor 陈鹏
 * @date 2020/6/18 16:41
 */
@RestController
@RequestMapping("Major")
public class MajorController {
    @Autowired
    private MajorService majorService;


    /**
     * 添加专业
     * @param major
     * @return ResultObj
     */
    @RequestMapping("MajorAdd")
    public ResultObj MajorAdd(Major major){
        try {
            majorService.insert(major);
            return ResultObj.Major_INSERT_YES;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.Major_INSERT_NO;
        }
    }

    /**
     * 查询全部专业
     * @param majorVo
     * @return DataGridView
     */
    @RequestMapping("MajorList")
    public DataGridView MajorList(MajorVo majorVo){
        return majorService.MajorList(majorVo);
    }

    /**
     * 删除专业方法
     * @param id
     * @return ResultObj
     */
    @RequestMapping("Majordelete")
    public ResultObj Majordelete(Integer id){
        try {
            majorService.deleteByPrimaryKey(id);
            return ResultObj.Major_DELETE_YES;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.Major_DELETE_NO;
        }
    }

    /**
     * 批量删除专业方法
     * @param ids
     * @return ResultObj
     */
    @RequestMapping("MajordeleteBatch")
    public ResultObj MajordeleteBatch(Integer[] ids){
        try {
            for (Integer id : ids) {
                majorService.deleteByPrimaryKey(id);
            }
            return ResultObj.Major_DELETE_YES;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.Major_DELETE_NO;
        }
    }


    /**
     * 修改专业方法
     * @param major
     * @return ResultObj
     */
    @RequestMapping("MajorUpdateMajor")
    public ResultObj MajorUpdateMajor(Major major){
        try {
            majorService.updateByPrimaryKeySelective(major);
            return ResultObj.Major_UPDATE_YES;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.Major_UPDATE_NO;
        }
    }



}
